//
//  SharedExample+Source.swift
//  SwiftCode
//
//  Created by yuhus on 2023/10/17.
//

import Foundation
import UIKit
import LinkPresentation

final class ShareItems: NSObject, UIActivityItemSource {
  // 加载元数据时共享表将使用的占位符
  func activityViewControllerPlaceholderItem(_ activityViewController: UIActivityViewController) -> Any {
    return "PlaceholderItem"
  }
  
  func activityViewController(_ activityViewController: UIActivityViewController, itemForActivityType activityType: UIActivity.ActivityType?) -> Any? {
    return Bundle.main.url(forResource: "shareVideo", withExtension: "MP4")
  }
  
  // 元数据
  func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
    let metadata = LPLinkMetadata()
    metadata.originalURL = URL(string: "https://www.233leyuan.com")
    metadata.url = metadata.originalURL
    metadata.title = "Ava's video in The Night Fus 2023-07-18 #GPark.."
    metadata.imageProvider = NSItemProvider(contentsOf: Bundle.main.url(forResource: "shareImage", withExtension: "jpeg")!)
    return metadata
  }
}
